package org.jeecg.modules.wflow.workflow.config;

import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType;
import org.flowable.common.engine.api.delegate.event.FlowableEventDispatcher;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.spring.SpringProcessEngineConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;

/**
 * flowable全局监听器
 * @author : willian fu
 * @date : 2022/8/27
 */
@Configuration
public class FlowableGlobalListener implements ApplicationListener<ContextRefreshedEvent> {

    @Autowired
    private GlobalTaskListener globalTaskListener;

    @Autowired
    private RuntimeService runtimeService;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
      runtimeService.addEventListener(globalTaskListener, FlowableEngineEventType.PROCESS_COMPLETED);
    }
}
